#ifndef APP_H_
#define APP_H_

#include "protocol.h"
#include "file_read.h"

typedef struct{
	unsigned int file_size;
	char *filename;
}FileStuff;

/**
 * Gets char array, converts it to unsigned int
 * @param char array to convert
 * @return result
 */
unsigned int array_to_int(char * buf);
/**
 * Gets unsigned int, converts it to char array
 * @param unsigned int to convert
 * @return result
 */
char * int_to_array(unsigned int integer);
/**
 * used by receiver, processes and validates first packet sent by transmitter
 * which contains the name of the file to send and its size, saves result 
 * into instance of struct FileStuff
 * @param dataFrame = packet, len = its size
 * @return 1 if success, 0 otherwise
 */
unsigned int readFirstDataFrame(char * dataFrame, unsigned int len, FileStuff * f);
/**
 * receives a frame and calculates the result of bitwise XOR of all its bytes.
 * @param data = data to process, size = size of data, f = where to save
 * @return bitwise XOR of all bytes in data
 */
unsigned int calcBCC(char * data, unsigned int size);
/**
 * validates frame mean for llread.
 * @param buffer = frame, size = size of frame, seq = current sequence number 
 * @return 0 if invalid frame, 3 if DISC frame, 1 if valid info frame
  return 1 se trama valida
 */ 
unsigned int validateFrame(char * buffer, unsigned int size, unsigned int seq);

/**
 * responsible for saving frames, pass valid info frames to llread 
 * and passing valid DISC frames to sendDisconnected.
 * @param fd = file descriptor to tty device, 
 * dataFrame = pointer to where the frames are saved, 
 * seq = current sequence number
 * @return -1 if DISC frame, size of dataFrame if valid info frame
 */
unsigned int receiverMain(unsigned int fd, char * dataFrame, unsigned int seq);
#endif 
